package com.taxinfo.view.dataImport;

import com.taxinfo.pojo.dto.AssetAndLibDto;
import com.taxinfo.service.AssetAndLibService;
import com.taxinfo.utils.SpringUtil;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author wanghy
 * @version 1.0
 */
public class AssetAndLibTable extends TableView<AssetAndLibDto> {
    private String id;
    private final AssetAndLibService AssetAndLibService = (AssetAndLibService) SpringUtil.getBean("AssetAndLibServiceImpl");

    private final ObservableList<AssetAndLibDto> items = FXCollections.observableArrayList();

    private final TableColumn<AssetAndLibDto, String> compSubNo = new TableColumn<>("企业科目编码");
    private final TableColumn<AssetAndLibDto, String> compSubName = new TableColumn<>("企业科目名称");
    private final TableColumn<AssetAndLibDto, String> subNo = new TableColumn<>("标准科目编码");
    private final TableColumn<AssetAndLibDto, String> subName = new TableColumn<>("标准科目名称");
//    private final TableColumn<AssetAndLibDto, String>  subType = new TableColumn<>("标准科目类型");
//    private final TableColumn<AssetAndLibDto, String> taxDecNo = new TableColumn<>("税务申报科目编码");
//    private final TableColumn<AssetAndLibDto, String> taxSubName = new TableColumn<>("税务申报科目名称");
    private final TableColumn<AssetAndLibDto, BigDecimal> openBal = new TableColumn<>("期初余额");
    private final TableColumn<AssetAndLibDto, BigDecimal> endBal = new TableColumn<>("期末余额");

    public AssetAndLibTable(String id) {
        setItems(items);
        initColumns();
        showAllData(id);

    }

    private void initColumns() {

        compSubNo.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getCompSubNo()));
        compSubNo.setPrefWidth(100);
        compSubName.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getCompSubName()));
        compSubName.setPrefWidth(300);
        subNo.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getSubNo()));
        subNo.setPrefWidth(100);
        subName.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getSubName()));
        subName.setPrefWidth(300);
//        subType.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getSubType()));
//        subType.setPrefWidth(200);
        openBal.setCellValueFactory(param -> new SimpleObjectProperty(param.getValue().getOpenBal()));
        openBal.setPrefWidth(300);
        endBal.setCellValueFactory(param -> new SimpleObjectProperty(param.getValue().getEndBal()));
        endBal.setPrefWidth(300);

        ObservableList<TableColumn<AssetAndLibDto, ?>> cols = getColumns();
        cols.add(compSubNo);
        cols.add(compSubName);
        cols.add(subNo);
        cols.add(subName);
//        cols.add(subType);
//        cols.add(taxDecNo);
//        cols.add(taxSubName);
        cols.add(openBal);
        cols.add(endBal);
    }

    public void showAllData(String id) {
        items.clear();
        List<AssetAndLibDto> vos = AssetAndLibService.selectAllData(id);
        if (vos == null){
            return;
        }
        items.addAll(vos);
    }

}

